import 'package:drift/native.dart';
import 'package:drift/drift.dart';
import 'package:libflutter/db/Person.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;

part 'DBManager.g.dart';

@DriftDatabase(tables: [Person])
class DBManager extends _$DBManager {
  DBManager() : super(_openConnection());

  @override
  int get schemaVersion => 1;

  //插入一条数据
  Future<int> saveEmployee(PersonData companion) async {
    return await into(person).insert(companion);
  }
}

LazyDatabase _openConnection() {
  return LazyDatabase(() async {
    final dbFolder = await getApplicationDocumentsDirectory();
    final file = File(p.join(dbFolder.path, 'test.db'));
    return NativeDatabase(file);
  });
}
